<?php

/*
 * This file is part of the gedongdong/laravel_rbac_permission.
 *
 * (c) gedongdong <gedongdong2010@163.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace App\Validate;

use App\Http\Models\Users;
use App\Http\Models\ZhyReport;
use Illuminate\Validation\Rule;

class ReportUpdateValidate extends BaseValidate
{
    protected $rules = [];

    protected $message = [];// 自定义消息

    public function __construct($request)
    {
        parent::__construct($request);
        $this->rules = [
            // 'id' => 'required|numeric',
            'number' => 'required|max:100',
            'position' => 'required',
            'client' => 'required',
            'total_price' => 'required',
            'price' => 'required',
            'is_change' => ['required', Rule::in([0, 1])],
        ];

        $this->message = [
            // 'id.required' => 'ID参数不能为空',
            // 'id.numeric' => 'ID参数错误',
            'number.required' => '请输入报告编号',
            'position.required' => '请输入项目位置',
            'client.required' => '请输入委托方',
            'total_price.required' => '请输入总价',
            'price.required' => '请输入单价',
            'is_change.required' => '请选择物理结构是否变化',
            'is_change.in' => '物理结构是否变化参数不正确',
        ];
    }

    protected function customValidate()
    {
        
        if(empty($this->requestData['id'])){
            $report = ZhyReport::where(['number' => $this->requestData['number']])->exists();
            if($report){
                $this->validator->errors()->add('number', '报告编号已存在');
                return false;
            }
        }else{

        }
    }
}
